package mb.view;  

import java.awt.Color;
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.ImageIcon;
import mb.config.Para;                // +

public class AppAbout extends JDialog implements ActionListener {

  // {+
  private Para para = Para.getPara();

  private static String aboutTitle;
  private static String ok;
  // +}

  // {&
  private static String empty;
  private static String product;
  private static String version;
  private static String date;
  private static String author;
  // &}

  // {+
  {
    aboutTitle =    para.getT("aboutTitle");
    empty =         para.getT("empty");
    product =       para.getT("product");
    version =       para.getT("version");
    date =          para.getT("date");
    author =        para.getT("author");
    ok =            para.getT("ok");
  }
  // +}

  private static final String IMAGE_PATH = "images/aboutMagic.gif";

  private JPanel northPanel = new JPanel();
  private JPanel southPanel = new JPanel();
  private JPanel centerPanel = new JPanel();
  private JPanel westPanel = new JPanel();
  private JPanel eastPanel = new JPanel();

  private JPanel imagePanel = new JPanel();
  private JPanel textPanel  = new JPanel();

  private ImageIcon imageIcon = para.getImageIcon(IMAGE_PATH);  // &

  private JLabel label0     = new JLabel();  // +
  private JLabel label1     = new JLabel();
  private JLabel label2     = new JLabel();
  private JLabel label3     = new JLabel();
  private JLabel label4     = new JLabel();
  private JLabel imageLabel = new JLabel(imageIcon);

  private JButton button    = new JButton(ok);     // &

  private BorderLayout borderLayout1 = new BorderLayout();
  private BorderLayout borderLayout2 = new BorderLayout();
  private GridLayout gridLayout      = new GridLayout();
  private FlowLayout flowLayout      = new FlowLayout();

  public AppAbout(AppFrame parent) {
    super(parent);  // different from the default constructor
    try {
      this.init();
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
    this.pack();
  }

  private void init() throws Exception {
    this.setTitle(aboutTitle);            // &
    this.setResizable(false);

    Container cp = this.getContentPane();
    cp.setLayout(borderLayout1);
    cp.add(northPanel, BorderLayout.NORTH);
    cp.add(southPanel, BorderLayout.SOUTH);
    cp.add(centerPanel, BorderLayout.CENTER);
    cp.add(westPanel, BorderLayout.WEST);
    cp.add(eastPanel, BorderLayout.EAST);

    centerPanel.setLayout(borderLayout2);
    centerPanel.add(imagePanel, BorderLayout.NORTH);
    centerPanel.add(textPanel, BorderLayout.SOUTH);

    imagePanel.setBackground(Color.ORANGE);
    imagePanel.add(imageLabel);

    textPanel.setLayout(gridLayout);
    textPanel.setBackground(Color.ORANGE);
    gridLayout.setRows(5);        // &
    gridLayout.setColumns(1);
    label0.setText(empty);        // +
    label1.setText(product);
    label2.setText(version);
    label3.setText(date);
    label4.setText(author);
    textPanel.add(label0);        // +
    textPanel.add(label1);
    textPanel.add(label2);
    textPanel.add(label3);
    textPanel.add(label4);

    southPanel.setLayout(flowLayout);
    southPanel.add(button);
    button.addActionListener(this);
  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == button) {
    this.setVisible(false);
    this.dispose();
    }
  }

}


